import 'package:boss/common/common.dart';
import 'package:boss/provider/version_provider.dart';
import 'package:boss/ui/page/personalSettings/model/list_title_bean.dart';
import 'package:boss/ui/page/personalSettings/page/editStoreMessage/edit_store_message_page.dart';
import 'package:boss/ui/page/personalSettings/page/feedback/feedback_page.dart';
import 'package:boss/ui/page/personalSettings/widget/personal_setting_list_title.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:boss/util/version_util.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';

final List<ListTitleBean> _items = [
  ListTitleBean(
    title: '门店信息',
    icon: 'assets/image/store_icon.png',
    url: EditStoreMessagePage.pageName,
  ),
  ListTitleBean(
    title: '反馈建议',
    icon: 'assets/image/message_icon.png',
    url: FeedbackPage.pageName,
  ),
  ListTitleBean(
    title: '版本升级',
    icon: 'assets/image/app_version_up.png',
    value: Constant.appVersion,
    url: 'versionUp',
  ),
];

class PersonalSettingListTitleList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ShadowRadiusCard(
      margin: EdgeInsets.only(top: 120.w),
      child: Consumer<VersionProvider>(
        builder: (context, versionProvider, child) {
          return ListView.separated(
            padding: EdgeInsets.zero,
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              var current = _items[index];

              return PersonalSettingListTitle(
                data: current,
                isRedDot: current.url == 'versionUp' && versionProvider.isRedDotWarn,
                onTap: () async {
                  if (current.url == 'versionUp') {
                    VersionUtil.checkVersion(context);
                  } else {
                    Navigator.pushNamed(context, current.url);
                  }
                },
              );
            },
            separatorBuilder: (context, index) {
              bool isLast = index == _items.length;

              return isLast ? null : CustomDivider(margin: EdgeInsets.symmetric(horizontal: 20.w));
            },
            itemCount: _items.length,
          );
        },
      ),
    );
  }
}
